package com.huarui.action.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONObject;

import org.ewaf.framework.action.BaseAction;
import org.ewaf.framework.model.ListModel;

import com.huarui.action.service.ActionService;
import com.huarui.permission.dataobject.Action;
import com.huarui.user.model.SessionMessage;
import com.huarui.user.security.UserHolder;


public class ActionAction extends BaseAction {


	private static final long serialVersionUID = 1L;
	
	private Map<String,Object> resultMap=new HashMap<String, Object>();
	private ActionService actionManagerService;
	private String actionJson;
	private SessionMessage sm;
	private ListModel listModel=new ListModel();
	private Integer start;
	private Integer limit;
	public String save(){
		Action actionAction=(Action) JSONObject.toBean(JSONObject.fromObject(actionJson),Action.class);
		resultMap=actionManagerService.save(actionAction);
		return "success";
	}
	public Map<String, Object> getResultMap() {
		return resultMap;
	}
	@SuppressWarnings("unchecked")
	public String extList(){
		sm=UserHolder.getCurrentSessionMessage();
		listModel.setPage(start == null ? 0 : start / limit + 1);
		listModel.setPageSize(limit == null ? 10 : limit);
		Map<String, Object> map = new HashMap<String, Object>();
		List<Map> list=actionManagerService.pagingByCondition(listModel,map);
		resultMap.put("root", list);
		resultMap.put("totalProperty", listModel.getTotal());
		return "success";
	}
	
	public String getActionById(){
		
		return "success";
	}

	public void setActionManagerService(ActionService actionManagerService) {
		this.actionManagerService = actionManagerService;
	}
	public void setActionJson(String actionJson) {
		this.actionJson = actionJson;
	}
	public void setSm(SessionMessage sm) {
		this.sm = sm;
	}
	public void setListModel(ListModel listModel) {
		this.listModel = listModel;
	}
	public void setStart(Integer start) {
		this.start = start;
	}
	public void setLimit(Integer limit) {
		this.limit = limit;
	}

}
